<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>角色管理</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/treeview.jsp" %>
	<script type="text/javascript">
        var validateForm;
        function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            if(validateForm.form()){
                loading('正在提交，请稍等...');
                $("#inputForm").submit();
                return true;
            }

            return false;
        }

		$(document).ready(function(){
			$("#name").focus();
			validateForm = $("#inputForm").validate({
				rules: {
					name: {remote: "${ctx}/sys/role/checkName?oldName=" + encodeURIComponent("${role.name}")},
					enname: {remote: "${ctx}/sys/role/checkEnname?oldEnname=" + encodeURIComponent("${role.enname}")}
				},
				messages: {
					name: {remote: "角色名已存在"},
					enname: {remote: "英文名已存在"}
				},
				submitHandler: function(form){
					var ids = [], nodes = tree.getCheckedNodes(true);
					for(var i=0; i<nodes.length; i++) {
						ids.push(nodes[i].id);
					}
					$("#menuIds").val(ids);
					var ids2 = [], nodes2 = tree2.getCheckedNodes(true);
					for(var i=0; i<nodes2.length; i++) {
						ids2.push(nodes2[i].id);
					}
					$("#officeIds").val(ids2);
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});

			var setting = {check:{enable:true,nocheckInherit:true},view:{selectedMulti:false},
					data:{simpleData:{enable:true}},callback:{beforeClick:function(id, node){
						tree.checkNode(node, !node.checked, true, true);
						return false;
					}}};
			
			// 用户-菜单
			var zNodes=[
					<c:forEach items="${menuList}" var="menu">{id:"${menu.id}", pId:"${not empty menu.parent.id?menu.parent.id:0}", name:"${not empty menu.parent.id?menu.name:'权限列表'}"},
		            </c:forEach>];
			// 初始化树结构
			var tree = $.fn.zTree.init($("#menuTree"), setting, zNodes);
			// 不选择父节点
			tree.setting.check.chkboxType = { "Y" : "ps", "N" : "s" };
			// 默认选择节点
			var ids = "${role.menuIds}".split(",");
			for(var i=0; i<ids.length; i++) {
				var node = tree.getNodeByParam("id", ids[i]);
				try{tree.checkNode(node, true, false);}catch(e){}
			}
			// 默认展开全部节点
			tree.expandAll(true);
			
			// 用户-机构
			var zNodes2=[
					<c:forEach items="${officeList}" var="office">{id:"${office.id}", pId:"${not empty office.parent?office.parent.id:0}", name:"${office.name}"},
		            </c:forEach>];
			// 初始化树结构
			var tree2 = $.fn.zTree.init($("#officeTree"), setting, zNodes2);
			// 不选择父节点
			tree2.setting.check.chkboxType = { "Y" : "ps", "N" : "s" };
			// 默认选择节点
			var ids2 = "${role.officeIds}".split(",");
			for(var i=0; i<ids2.length; i++) {
				var node = tree2.getNodeByParam("id", ids2[i]);
				try{tree2.checkNode(node, true, false);}catch(e){}
			}
			// 默认展开全部节点
			tree2.expandAll(true);
			// 刷新（显示/隐藏）机构
			refreshOfficeTree();
			$("#dataScope").change(function(){
				refreshOfficeTree();
			});
		});
		function refreshOfficeTree(){
			if($("#dataScope").val()==9){
				$("#officeTree").show();
			}else{
				$("#officeTree").hide();
			}
		}
	</script>
</head>
<body>
	<form:form id="inputForm" modelAttribute="role" action="${ctx}/sys/role/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
    <table class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
        <tbody>

        <tr>
            <td class="width-15 active"><label class="pull-right"><font color="red">*</font>角色名称:</label></td>
            <td class="width-35">
                <%--<input id="oldName" name="oldName" type="hidden" value="人事">--%>
                <%--<input id="name" name="name" class="form-control required valid" type="text" value="人事" maxlength="50" aria-required="true" aria-invalid="false"></td>--%>
                <input id="oldName" name="oldName" type="hidden" value="${role.name}">
                <form:input path="name" htmlEscape="false" maxlength="50" class="form-control input-large required valid"/>
            <td class="width-15 active"><label class="pull-right"><font color="red">*</font>英文名称:</label></td>
            <td class="width-35">

                <%--<input id="oldEnname" name="oldEnname" type="hidden" value="hr">--%>
                <%--<input id="enname" name="enname" class="form-control required valid" type="text" value="hr" maxlength="50" aria-required="true" aria-invalid="false"></td>--%>
                    <input id="oldEnname" name="oldEnname" type="hidden" value="${role.enname}">
                <form:input path="enname" htmlEscape="false" maxlength="50" class="form-control input-large required valid"/>
        </tr>
        <tr>
            <td class="width-15 active"><label class="pull-right">是否可用</label></td>
            <td class="width-35">
                <form:select path="useable" cssClass="form-control input-large">
                    <form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                </form:select>

                    <%--<select id="useable" name="useable" class="form-control input-large select2-hidden-accessible" tabindex="-1" aria-hidden="true">--%>
                        <%--<option value="1" selected="selected">是</option><option value="0">否</option>--%>
                    <%--</select>--%>

                    <%--<span class="select2 select2-container select2-container--default" dir="ltr" style="width: 174px;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-useable-container"><span class="select2-selection__rendered" id="select2-useable-container" title="是">是</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>--%>

                <%--<select id="useable" name="useable" class="form-control input-large select2-hidden-accessible" tabindex="-1" aria-hidden="true">--%>
                    <%--<option value="1" selected="selected">是</option><option value="0">否</option>--%>
                <%--</select>--%>
                <span class="help-inline">“是”代表此数据可用，“否”则表示此数据不可用</span>

                <%--<select id="useable" name="useable" class="form-control input-large select2-hidden-accessible" tabindex="-1" aria-hidden="true">--%>
                <%--<option value="1" selected="selected">是</option><option value="0">否</option>--%>
            <%--</select>--%>
                <%--<span class="select2 select2-container select2-container--default" dir="ltr" style="width: 174px;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-useable-container"><span class="select2-selection__rendered" id="select2-useable-container" title="是">是</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>--%>

            </td>

            <td class="width-15 active"><label class="pull-right">数据范围:</label></td>
            <td class="width-35">
                <form:select path="dataScope" cssClass="form-control input-large">
                    <form:options items="${fns:getDictList('sys_data_scope')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                </form:select>
                <span class="help-inline">特殊情况下，设置为“按明细设置”，可进行跨机构授权</span>


                <%--<select id="dataScope" name="dataScope" class="form-control input-large select2-hidden-accessible" tabindex="-1" aria-hidden="true">--%>
                <%--<option value="1">所有数据</option><option value="5">所在部门数据</option><option value="8" selected="selected">仅本人数据</option>--%>
            <%--</select><span class="select2 select2-container select2-container--default" dir="ltr" style="width: 174px;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-dataScope-container"><span class="select2-selection__rendered" id="select2-dataScope-container" title="仅本人数据">仅本人数据</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>--%>

            </td>
        </tr>
        <tr>
            <td class="width-15 active"><label class="pull-right">角色类型:</label></td>
            <td class="width-35" colspan="3">
                <form:select path="roleType" cssClass="form-control input-large">
                    <form:option value="assignment">任务分配</form:option>
                    <form:option value="security-role">管理角色</form:option>
                    <form:option value="user">普通角色</form:option>
                </form:select>
                <span class="help-inline" title="activiti有3种预定义的组类型：security-role、assignment、user 如果使用Activiti Explorer，需要security-role才能看到manage页签，需要assignment才能claim任务">
					工作流组用户组类型（任务分配：assignment、管理角色：security-role、普通角色：user）</span>



                <%--<select id="roleType" name="roleType" class="form-control  select2-hidden-accessible" tabindex="-1" aria-hidden="true">--%>
                    <%--<option value="assignment">任务分配</option>--%>
                    <%--<option value="security-role">管理角色</option>--%>
                    <%--<option value="user" selected="selected">普通角色</option>--%>
                <%--</select><span class="select2 select2-container select2-container--default" dir="ltr" style="width: 104px;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-roleType-container"><span class="select2-selection__rendered" id="select2-roleType-container" title="普通角色">普通角色</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>--%>
                <%--<span class="help-inline" title="activiti有3种预定义的组类型：security-role、assignment、user 如果使用Activiti Explorer，需要security-role才能看到manage页签，需要assignment才能claim任务">--%>
						<%--工作流组用户组类型（任务分配：assignment、管理角色：security-role、普通角色：user）</span>--%>
            </td>
        </tr>
        <tr>
            <td class="width-15 active"><label class="pull-right">是否系统数据:</label></td>
            <td class="width-35" colspan="3">
                <form:select path="sysData" cssClass="form-control input-large">
                    <form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                </form:select>
                <span class="help-inline">“是”代表此数据只有超级管理员能进行修改，“否”则表示拥有角色修改人员的权限都能进行修改</span>

                <%--<select id="sysData" name="sysData" class="form-control  select2-hidden-accessible" tabindex="-1" aria-hidden="true">--%>
                <%--<option value="1" selected="selected">是</option><option value="0">否</option>--%>
            <%--</select><span class="select2 select2-container select2-container--default" dir="ltr" style="width: 62px;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-sysData-container"><span class="select2-selection__rendered" id="select2-sysData-container" title="是">是</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>--%>
                <%--<span class="help-inline">“是”代表此数据只有超级管理员能进行修改，“否”则表示拥有角色修改人员的权限都能进行修改</span>--%>
            </td>
        </tr>

        <tr>
            <td class="width-15 active"><label class="pull-right">归属机构:</label></td>
            <td class="width-35">
                <sys:treeselect id="office" name="office.id" value="${role.office.id}" labelName="office.name" labelValue="${role.office.name}"
                    title="机构" url="/sys/office/treeData" cssClass="required"/>
            </td>
            <td class="width-15 active"><label class="pull-right">备注:</label></td>
            <td class="width-35">
                <form:textarea path="remarks" htmlEscape="false" rows="3" maxlength="200" class="form-control "/>
                <%--<textarea id="remarks" name="remarks" maxlength="200" class="form-control " rows="3"></textarea>--%>
            </td>
        </tr>

        </tbody>
    </table>

        <form:hidden path="menuIds"/>
        <div id="officeTree" class="ztree" style="margin-left:100px;margin-top:3px;float:left;"></div>
        <form:hidden path="officeIds"/>


		<%--<div class="control-group">--%>
			<%--<label class="control-label">归属机构:</label>--%>
			<%--<div class="controls">--%>
                <%--<sys:treeselect id="office" name="office.id" value="${role.office.id}" labelName="office.name" labelValue="${role.office.name}"--%>
					<%--title="机构" url="/sys/office/treeData" cssClass="required"/>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">角色名称:</label>--%>
			<%--<div class="controls">--%>
				<%--<input id="oldName" name="oldName" type="hidden" value="${role.name}">--%>
				<%--<form:input path="name" htmlEscape="false" maxlength="50" class="required"/>--%>
				<%--<span class="help-inline"><font color="red">*</font> </span>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">英文名称:</label>--%>
			<%--<div class="controls">--%>
				<%--<input id="oldEnname" name="oldEnname" type="hidden" value="${role.enname}">--%>
				<%--<form:input path="enname" htmlEscape="false" maxlength="50" class="required"/>--%>
				<%--<span class="help-inline"><font color="red">*</font> 工作流用户组标识</span>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">角色类型:</label>--%>
			<%--<div class="controls">&lt;%&ndash;--%>
				<%--<form:input path="roleType" htmlEscape="false" maxlength="50" class="required"/>--%>
				<%--<span class="help-inline" title="activiti有3种预定义的组类型：security-role、assignment、user 如果使用Activiti Explorer，需要security-role才能看到manage页签，需要assignment才能claim任务">--%>
					<%--工作流组用户组类型（security-role：管理员、assignment：可进行任务分配、user：普通用户）</span> &ndash;%&gt;--%>
				<%--<form:select path="roleType" class="input-medium">--%>
					<%--<form:option value="assignment">任务分配</form:option>--%>
					<%--<form:option value="security-role">管理角色</form:option>--%>
					<%--<form:option value="user">普通角色</form:option>--%>
				<%--</form:select>--%>
				<%--<span class="help-inline" title="activiti有3种预定义的组类型：security-role、assignment、user 如果使用Activiti Explorer，需要security-role才能看到manage页签，需要assignment才能claim任务">--%>
					<%--工作流组用户组类型（任务分配：assignment、管理角色：security-role、普通角色：user）</span>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">是否系统数据:</label>--%>
			<%--<div class="controls">--%>
				<%--<form:select path="sysData">--%>
					<%--<form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/>--%>
				<%--</form:select>--%>
				<%--<span class="help-inline">“是”代表此数据只有超级管理员能进行修改，“否”则表示拥有角色修改人员的权限都能进行修改</span>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">是否可用</label>--%>
			<%--<div class="controls">--%>
				<%--<form:select path="useable" cssClass="form-control input-large">--%>
					<%--<form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/>--%>
				<%--</form:select>--%>
				<%--<span class="help-inline">“是”代表此数据可用，“否”则表示此数据不可用</span>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">数据范围:</label>--%>
			<%--<div class="controls">--%>
				<%--<form:select path="dataScope" class="input-medium">--%>
					<%--<form:options items="${fns:getDictList('sys_data_scope')}" itemLabel="label" itemValue="value" htmlEscape="false"/>--%>
				<%--</form:select>--%>
				<%--<span class="help-inline">特殊情况下，设置为“按明细设置”，可进行跨机构授权</span>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">角色授权:</label>--%>
			<%--<div class="controls">--%>
				<%--<div id="menuTree" class="ztree" style="margin-top:3px;float:left;"></div>--%>
				<%--<form:hidden path="menuIds"/>--%>
				<%--<div id="officeTree" class="ztree" style="margin-left:100px;margin-top:3px;float:left;"></div>--%>
				<%--<form:hidden path="officeIds"/>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">备注:</label>--%>
			<%--<div class="controls">--%>
				<%--<form:textarea path="remarks" htmlEscape="false" rows="3" maxlength="200" class="input-xlarge"/>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="form-actions">--%>
			<%--<c:if test="${(role.sysData eq fns:getDictValue('是', 'yes_no', '1') && fns:getUser().admin)||!(role.sysData eq fns:getDictValue('是', 'yes_no', '1'))}">--%>
				<%--<shiro:hasPermission name="sys:role:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>--%>
			<%--</c:if>--%>
			<%--<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>--%>
		<%--</div>--%>
	</form:form>
</body>
</html>